﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="qlNews.ascx.cs" Inherits="admin_qlNews" %>
<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>
<style type="text/css">
    .style1
    {
        width: 98px;
    }
    .style2
    {
        width: 434px;
    }
    .style3
    {
        width: 98px;
        height: 59px;
    }
    .style4
    {
        width: 434px;
        height: 59px;
    }
    .style5
    {
        height: 59px;
    }
</style>
<center>
<table width="100%">
    <tr>
        <td class="style3">Ngôn ngữ: </td>
        <td class="style4">
            <asp:DropDownList ID="ddlLang" runat="server" 
                DataSourceID="SqlDataSource3" DataTextField="lang" DataValueField="id" 
                Height="25px" ValidationGroup="insert" Width="115px">
            </asp:DropDownList>
            <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
                ConnectionString="<%$ ConnectionStrings:canhbuomxanhconnectionstring %>" 
                SelectCommand="SELECT * FROM [Languages]"></asp:SqlDataSource>
        </td>
        <td class="style5">
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                ErrorMessage="*" ControlToValidate="ddlLang" ValidationGroup="insert">Chưa Chọn Ngôn Ngữ</asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td class="style3">Loại tin: </td>
        <td class="style4">
            <asp:DropDownList ID="newstype" runat="server" DataSourceID="SqlDataSource1" 
                DataTextField="description" DataValueField="id" AutoPostBack="True" 
                Height="28px" ValidationGroup="insert" Width="225px">
            </asp:DropDownList>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:canhbuomxanhconnectionstring %>" 
                SelectCommand="SELECT * FROM [NewsType]"></asp:SqlDataSource>
        </td>
        <td class="style5">
            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
                ControlToValidate="newstype" ErrorMessage="Chưa chọn loại tin"></asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td class="style1">Tiêu đề: </td>
        <td class="style2">
            <asp:TextBox ID="title" runat="server" ValidationGroup="insert"></asp:TextBox>
            </td>
        <td>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                ErrorMessage="*" ControlToValidate="title" ValidationGroup="insert">Chưa nhập tiêu đề</asp:RequiredFieldValidator>
            </td>
    </tr>
    <tr>
        <td class="style1">Miêu tả: </td>
        <td class="style2">
            <asp:TextBox ID="des" runat="server" MaxLength="5000" Rows="5" 
                TextMode="MultiLine" ValidationGroup="insert" Width="335px"></asp:TextBox>
        </td>
        <td>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                ErrorMessage="*" ControlToValidate="des" ValidationGroup="insert">Chưa nhập miêu tả</asp:RequiredFieldValidator>
        </td>
    </tr>
    <tr>
        <td class="style1">Ảnh: </td>
        <td class="style2">
            <asp:FileUpload ID="fulImage" runat="server" />
        </td>
        <td>
            <asp:Label ID="lbImage" runat="server" ForeColor="Red"></asp:Label>
        </td>
    </tr>
    <tr>
        <td class="style1">Nội dung: </td>
        <td class="style2">
            <fckeditorv2:fckeditor ID="fckContent" runat="server" BasePath="~/fckeditor/">
            </fckeditorv2:fckeditor>
        </td>
        <td>
            <asp:HiddenField ID="hdfContent" runat="server" />
            <asp:HiddenField ID="hdfNewID" runat="server" />
            <asp:HiddenField ID="hdfImage" runat="server" />
        </td>
    </tr>
     <tr>
        <td class="style1">&nbsp;</td>
        <td class="style2">
            &nbsp;</td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td><center></center></td>
        <td class="style2">
            <asp:Button runat="server" ID="addbt" Text="Thêm" 
                ValidationGroup="insert" onclick="addbt_Click"/></td>
        <td>&nbsp;</td>
    </tr>
</table>
</center>
<br />
<br />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
        AutoGenerateColumns="False" AllowSorting="True"
        CellPadding="4" ForeColor="#333333" GridLines="None"
        PageSize="5" Width="100%" onrowcreated="GridView1_RowCreated" 
        onrowediting="GridView1_RowEditing" 
    onrowcommand="GridView1_RowCommand" 
    DataSourceID="SqlDataSource2" DataKeyNames="id,lang" 
    onrowdeleted="GridView1_RowDeleted" onrowdeleting="GridView1_RowDeleting">
        <RowStyle BackColor="#EFF3FB" VerticalAlign="Middle" />
        <EmptyDataRowStyle VerticalAlign="Middle" />
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="White" ForeColor="#459300" HorizontalAlign="Center" />
        <EmptyDataTemplate>
             <asp:Label ID="Label3" runat="server" Text="Chưa có dữ liệu"></asp:Label>
        </EmptyDataTemplate>
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#57A000" Font-Bold="True" ForeColor="White" />
        <Columns>
            <asp:TemplateField HeaderText="id" SortExpression="id" Visible="False">
                <EditItemTemplate>
                    <asp:Label ID="id" runat="server" Text='<%# Eval("id") %>'></asp:Label>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="id" runat="server" Text='<%# Bind("id") %>'></asp:Label>
                </ItemTemplate>
                <ItemStyle HorizontalAlign="Center" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Ngôn ngữ" SortExpression="lang">
                <EditItemTemplate>
                    <asp:Label ID="lang" runat="server" Text='<%# Eval("lang") %>'></asp:Label>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lang" runat="server" Text='<%# Bind("lang") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Tiêu đề" SortExpression="title">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("title") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("title") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Miêu tả" SortExpression="description">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("description") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label4" runat="server" Text='<%# Bind("description") %>'></asp:Label>
                </ItemTemplate>
                <ItemStyle HorizontalAlign="Center" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Nội dung" SortExpression="content">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("content") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label5" runat="server" Text='<%# Bind("content") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="imageUrl" SortExpression="imageUrl" Visible="False">
                <EditItemTemplate>
                    <asp:Label ID="imageUrl" runat="server" Text='<%# Eval("imageUrl") %>'></asp:Label>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="imageUrl" runat="server" Text='<%# Bind("imageUrl") %>'></asp:Label>
                </ItemTemplate>
                <ItemStyle HorizontalAlign="Center" />
            </asp:TemplateField>
            <asp:CommandField ButtonType="Button" EditText="Sửa" ShowEditButton="True" />
            <asp:CommandField ButtonType="Button" DeleteText="Xoá" 
                ShowDeleteButton="True" />
        </Columns>
        <EditRowStyle BackColor="#003366" VerticalAlign="Middle" />
        <AlternatingRowStyle BackColor="White" />
    </asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
    ConnectionString="<%$ ConnectionStrings:canhbuomxanhconnectionstring %>" 
    SelectCommand="SELECT * FROM [News] ORDER BY [id] DESC"
    DeleteCommand="DELETE FROM [News] WHERE [id] = @id AND [lang] = @lang" 
        InsertCommand="INSERT INTO [News] ([id], [lang], [title], [description], [content], [newsTypeId],[imageUrl]) VALUES (@id, @lang, @title, @description, @content, @newsTypeId, @imageUrl)" 
    >
    <DeleteParameters>
            <asp:Parameter Name="id" Type="Int64" />
            <asp:Parameter Name="lang" Type="String" />
        </DeleteParameters>
        <InsertParameters>
            <asp:ControlParameter ControlID="hdfNewID" Name="id" PropertyName="Value" 
                Type="Int64" />
            <asp:ControlParameter ControlID="ddlLang" Name="lang" 
                PropertyName="SelectedValue" Type="String" />
            <asp:ControlParameter ControlID="title" Name="title" PropertyName="Text" 
                Type="String" />
            <asp:ControlParameter ControlID="des" Name="description" PropertyName="Text" 
                Type="String" />
            <asp:ControlParameter ControlID="hdfContent" Name="content" 
                PropertyName="Value" Type="String" />
            <asp:ControlParameter ControlID="newstype" Name="newsTypeId" 
                PropertyName="SelectedValue" Type="Int64" />
            <asp:ControlParameter ControlID="hdfImage" Name="imageUrl" 
                PropertyName="Value" />
        </InsertParameters>
</asp:SqlDataSource>

